package com.leung.machine.config;


import com.leung.machine.action.*;
import com.leung.machine.enums.States;
import com.leung.machine.stateListener.OrderStateMachineListener;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.statemachine.listener.StateMachineListener;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 丨一
 * @version 1.0
 * @title StateActionConfig
 * @description:
 * @date 2025/10/7 上午10:09
 */

@Configuration
public class StateActionConfig {

    @Bean
    public Map<States, StateAction> actionMap(NewStateAction newStateAction,
                                              PendingStateAction pendingStateAction,
                                              CompletedStateAction completedStateAction,
                                              FailedStateAction failedStateAction) {
        Map<States, StateAction> map = new HashMap<>();
        map.put(States.NEW, newStateAction);
        map.put(States.PENDING, pendingStateAction);
        map.put(States.COMPLETED, completedStateAction);
        map.put(States.FAILED, failedStateAction);
        return map;
    }


    @Bean
    public StateMachineListener orderStateMachineListener(Map<States, StateAction> actionMap) {
        return new OrderStateMachineListener(actionMap);
    }


}
